package com.lg.concurrent.share_parameter;

import lombok.SneakyThrows;

import java.util.HashMap;
import java.util.concurrent.CountDownLatch;

public class ThreadLocalThread extends Thread {
    CountDownLatch countDownLatch;
    ThreadLocalThread(CountDownLatch countDownLatch){
        this.countDownLatch = countDownLatch;
    }
    @SneakyThrows
    @Override
    public void run() {
        try {
            countDownLatch.countDown();
            countDownLatch.await();

            HashMap<String, String> map = new HashMap<>();
            map.put("com.lg.aa", ""+Thread.currentThread().getName());
            ThreadLocalParameter.local.set(map);
            step();
            ThreadLocalTest threadLocalTest = new ThreadLocalTest();
            threadLocalTest.step();
        } finally {
            ThreadLocalParameter.local.remove();
        }
    }
    public void step() {
        System.out.println(ThreadLocalParameter.local.get().get("com.lg.aa"));
    }
}
